#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int n, q;
int arr[N];
int f[N], g[N];
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> arr[i];
    f[1] = arr[1];
    for (int i = 2; i <= n; i++)
    {
        int x = arr[i];
        f[i] = max(f[i - 1], x);
        if (x >= f[i - 1]) g[i] = f[i - 1];
        else if (x >= g[i - 1]) g[i] = x;
        else g[i] = g[i - 1];
    }
    cin >> q;
    while (q--)
    {
        int x = 0;
        cin >> x;
        cout << g[x] << endl;
    }
    return 0;
}

#include<iostream>
using namespace std;

const int N = 1010;
int n, q, x;
int row, col;
int arr[N][N];

void row_change()
{
    for (int i = 0; i < n / 2; i++)
    {
        for (int j = 0; j < n; j++)
        {
            swap(arr[i][j], arr[n - i - 1][j]);
        }
    }
}
void col_change()
{
    for (int j = 0; j < n / 2; j++)
    {
        for (int i = 0; i < n; i++)
        {
            swap(arr[i][j], arr[i][n - j - 1]);
        }
    }
}
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin >> arr[i][j];
        }
    }
    cin >> q;
    while (q--)
    {
        cin >> x;
        if (x == 1) row++, col++;
        else if (x == 2) row++;
    }
    row %= 2;
    col %= 2;
    if (row) row_change();
    if (col) col_change();
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cout << arr[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

#include <iostream>
#include<cstring>
using namespace std;

typedef long long LL;
const int N = 1e3 + 10;
LL n, k;
LL a[N];
LL dp[N][N];

int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];

    memset(dp, -0x3f, sizeof dp);
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < k; j++)
        {
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][(j - a[i] % k + k) % k] + a[i]);
        }
    }
    if (dp[n][0] <= 0) cout << -1 << endl;
    else cout << dp[n][0] << endl;

    return 0;
}